package com.schedule.controller;


import com.schedule.pojo.Competition;
import com.schedule.pojo.EventArrange;
import com.schedule.pojo.RespBean;
import com.schedule.service.ICompetitionService;
import com.schedule.service.IEventArrangeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author star
 * @since 2022-03-05
 */
@RestController
@RequestMapping("/arrange")
public class EventArrangeController {

    @Autowired
    IEventArrangeService eventArrangeService;
    @Autowired
    ICompetitionService competitionService;


    @ApiOperation(value = "编排赛事")
    @GetMapping("/arrangeAlgorithm/{eventDays}")
    public  RespBean arrangeEvents(@PathVariable Integer eventDays){
        List<EventArrange> eventArranges=eventArrangeService.list();
        List<Competition> competition=competitionService.list();
        if(eventArranges.size()!=competition.size()){
            eventArranges = eventArrangeService.algori(eventDays);
            if(0==eventArranges.size()){
                return RespBean.error("编排失败，赛事或运动员为空！");
            }
            boolean res = eventArrangeService.updateArrangeResult(1, eventArranges);
            if(res){
                return RespBean.success("编排成功！");
            }
            return RespBean.error("编排失败！");
        }
        return RespBean.success("编排成功！");
    }

//    @ApiOperation(value = "获取编排结果")
//    @GetMapping("/arrangeResult")
//    public List<EventArrange> getAllArrangeResult(){
//
//        if(eventArranges.size()==competition.size()){
//            return eventArranges;
//        }
//        eventArranges = eventArrangeService.algori(eventDays);
//    }
}
